﻿using Microsoft.EntityFrameworkCore;
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace EntityFramework.Core
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var context=new MyDbContext())
            {
                context.Database.Migrate();
            }
            Console.WriteLine("Hello World!");
        }
    }

    //数据为上下文 DbContext
    //1生成一次迁移
    //2因为要修改第一次的东西。所以再次生成迁移 remove-migration
   public class MyDbContext : DbContext
    {
        public DbSet<Car> Cars { get; set; }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);
            //配置数据库连接字符串
            //UserMySql().....所有。
            optionsBuilder.UseSqlServer("Data Source=.;Initial Catalog=Ef-Test;Integrated Security=True");
        }
    }

    [Table("Car1")]
    public class Car
    {
        /// <summary>
        /// 主键
        /// [Key] 代表当前属性为主键
        /// EF 它会有一个约定。每个类的 Id名字的属性为主键
        /// </summary>
    
        public int Id { get; set; }

        /// <summary>
        /// 汔车名字
        /// </summary> 
        public string Name { get; set; }


        public string Age { get; set; }

        public string Remarks { get; set; }
        public string  T1 { get; set; }
        public string T2 { get; set; }

        public string NewName { get; set; }
    }
}
